<template>
  <div>
    <!-- <h1>当前求和为：{{ sum }}</h1>
    <h3>bigSum：{{ sum * 10 }}</h3> -->

    <!-- <h1>当前求和为：{{ $store.state.sum }}</h1>
    <h3>bigSum：{{ $store.getters.bigSum }}</h3> -->

    <h1>当前求和为：{{ sum }}</h1>
    <h3>bigSum：{{ bigSum }}</h3>
    <div>
      <select v-model="initValue">
        <option :value="1">1</option>
        <option :value="2">2</option>
        <option :value="3">3</option>
      </select>
      <!-- <button @click="increment">+</button>
      <button @click="decrement">-</button>
      <button @click="incrementOdd">当前求和为奇数再加</button>
      <button @click="incrementDelay">延迟1秒再加</button> -->

      <button @click="INCREMENT(initValue)">+</button>
      <button @click="decrement(initValue)">-</button>
      <button @click="incrementOdd(initValue)">当前求和为奇数再加</button>
      <button @click="incrementDelay(initValue)">延迟1秒再加</button>
    </div>
  </div>
</template>

<script>
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
export default {
  name: 'MyCategory', 
  /* data() {
    return {
      sum: 0,
      initValue: 1
    }
  }, */
  data() {
    return {
      initValue: 1
    }
  },
  computed: {
    ...mapState(['sum']),
    // ...mapState({sum: 'sum'}),
    ...mapGetters(['bigSum']),
    // ...mapGetters({bigSum: 'bigSum'})
  },
  methods: {
    /* increment() {
      this.sum += this.initValue
    },
    decrement() {
      this.sum -= this.initValue
    },
    incrementOdd() {
      if(this.sum % 2) {
        this.sum += this.initValue
      }
    },
    incrementDelay() {
      setTimeout(() => {
        this.sum += this.initValue
      }, 1000);
    }, */

    /* increment() {
      this.$store.commit('INCREMENT', this.initValue)
    },
    decrement() {
      this.$store.commit('DECREMENT', this.initValue)
    },
    incrementOdd() {
      this.$store.dispatch('incrementOdd', this.initValue)
    },
    incrementDelay() {
      this.$store.dispatch('incrementDelay', this.initValue)
    }, */

    ...mapMutations(['INCREMENT']),
    ...mapMutations({decrement: 'DECREMENT'}),
    ...mapActions(['incrementOdd']),
    ...mapActions({incrementDelay: 'incrementDelay'})
  },
  mounted() {
    console.log(this)
  }
}
</script>